<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="org.springframework.security.core.context.*, org.springframework.security.core.*,org.springframework.security.core.userdetails.UserDetails, in.smartbillpay.web.models.SBPUser,in.smartbillpay.web.models.Authority" %>
<%@ include file="/WEB-INF/views/public/main.jsp" %>
     
        <div id="topbar" class="clearfix">
            
            <div class="container_12">
                
                <div class="grid_5">
                    <p><a href="index.html"><strong>Smart Bill Pay</strong></a> is a smart way to pay your bills</p>
                </div><!-- //grid_5 -->

                <div class="grid_5">
                    <p>phone: <strong>201-283-0781</strong> email: <strong><a href="#">info@smartbillpay.in</a></strong></p>
                </div><!-- //grid_5 -->
                
                <div class="grid_2">
                   <p style="float:right"> <strong style="color:white;">Welcome 
                   <% 
                   String homepageUrl = (String)pageContext.getAttribute("rootUrl");
                   String username ="Guest";
                   Object principal ;
          		 SecurityContext securityContext = SecurityContextHolder.getContext();
          		 if(securityContext != null) {
          			 Authentication authentication = securityContext.getAuthentication();
          			 if(authentication != null) {
          				 principal = authentication.getPrincipal();
          				 if (principal != null && principal instanceof UserDetails) {
                              username = ((UserDetails)principal).getUsername();
                             } 
          				 if(principal != null && principal instanceof SBPUser){
          					 SBPUser user = (SBPUser)principal;
          					 username = user.getFirstName() + " " + user.getLastName();
          					 for(Authority authority: user.getAuthorityList()){
          						 if(authority.getName().equalsIgnoreCase("ROLE_ADMIN")){
          							homepageUrl += "secure/admin/";
          							break;
          						 }
          						 else if(authority.getName().equalsIgnoreCase("ROLE_AGENT")){
          							homepageUrl += "secure/agent/";
          							break;
          						 }
          						 
          					 }
          				 }
          			 }
          		 }
                   %>
                   <%=username %>
                  </strong> </p> 
                </div><!-- //grid_2 -->
                
            </div><!-- //container_12 -->
            
        </div><!-- //topbar -->
            
            
		<div id="header" class="clearfix" style="padding:0px;top:0px;height:80px;">          
        	
        	<div class="container_12" >
            	
           		<div class="grid_12" style="padding:0px;height:0px;" id="header-container">
                   <div id="logo" >
                        <h1><a href="<%=homepageUrl%>" title="Go to the home page"><img src="${resourceUrl}/images/logo.png" alt="Logo" /></a></h1>
                  </div>
                   <!-- //logo -->
                     <ul class="sf-menu" style="top:20px">
					 	<li><a href="<%=homepageUrl%>">Home</a></li>
					 	<li>	<a href="${rootUrl}howitworks">How it works</a></li>
					 	<li>
                        	<a href="${rootUrl}contact/location">Contact Us</a>
                        </li>
					 	<li>	<a href="${rootUrl}public/register/agent/">Register</a>
					 		
					 	</li>
					 	<li>	
					 		<%
					 			if(username == "Guest"){ %>
					 			
					 			<a href="${rootUrl}login">Login</a>
					 			<%
					 			}
					 			else  {%>
					 				<a href="${rootUrl}j_spring_security_logout">Logout</a>
					 			<% }%>	
					 	</li>
					 	
                        
                       
					</ul>
					
            	</div><!-- //grid_12 -->
            
			</div><!-- //container_12 -->
            
        
        </div><!-- //header -->